package client

import (
	"github.com/smallnest/rpcx/client"
	"github.com/smallnest/rpcx/protocol"
	"sync"
	"time"
	"wzgames/internal/gloader"
	"wzgames/internal/services"
)

// uc wallet rpc client

var (
	walletPool *client.XClientPool
	walletOnce sync.Once
)

func InitDouWalletClient() {
	option := client.DefaultOption
	option.ConnectTimeout = 5 * time.Second
	option.Heartbeat = true
	option.HeartbeatInterval = 15 * time.Second
	option.Retries = 1
	option.SerializeType = protocol.ProtoBuffer
	d := gloader.NewServiceDiscovery(services.RPCxServiceDouWallet)
	walletPool = client.NewXClientPool(3, services.RPCxServiceDouWallet, client.Failfast, client.RoundRobin, d, option)
}

func GetDouWalletClient() client.XClient {
	if walletPool == nil {
		walletOnce.Do(func() {
			InitDouWalletClient()
		})
	}
	return walletPool.Get()
}

func CloseDouWalletClient() {
	if walletPool != nil {
		walletPool.Close()
	}
}
